package com.jake.rabbitbootdemo.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class TopicConfig {

    @Bean
    public Queue topicQueueAccurate() {
        return new Queue("jake.topic.queue.accurate");
    }

    @Bean
    public Queue topicQueueSingle() {
        return new Queue("jake.topic.queue.single");
    }

    @Bean
    public Queue topicQueueAny() {
        return new Queue("jake.topic.queue.any");
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("jake.topic.exchange");
    }

    @Bean
    public Binding bindWithAccurateMatcher() {
        return BindingBuilder.bind(topicQueueAccurate()).to(topicExchange()).
                with("jake.topic.routingKey.accurate");
    }

    @Bean
    public Binding bindWithSingleWordMatcher() {
        return BindingBuilder.bind(topicQueueSingle()).to(topicExchange()).
                with("jake.topic.routingKey.*");
    }

    @Bean
    public Binding bindWithAnyWordMatcher() {
        return BindingBuilder.bind(topicQueueAny()).to(topicExchange()).
                with("jake.topic.#");
    }

}
